<?php
/**
 * Created by PhpStorm.
 * Script Name: MiniReg.php
 * Create: 2023/12/11 8:59
 * Description:
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace plugin\wechat\app\service;


use plugin\wechat\app\model\MiniReg as RegM;

class MiniReg extends Common
{
    static $model = null;
    
    static function status($id = null){
        $list = [
            0 => '注册失败',
            1 => '进行中',
            2 => '注册完成'
        ];
        return isset($list[$id]) ? $list[$id] : $list;
    }

    static function model(){
        if(is_null(self::$model)){
            self::$model = new RegM();
        }
        return self::$model;
    }

    /**
     * 企业类型
     * @param null $id
     * @return array|mixed
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function codeTypes($id = null){
        $list = [
            1 => '统一社会信用代码（18 位）',
            2 => '组织机构代码（9 位 xxxxxxxx-x）',
            3 => '营业执照注册号(15 位)'
        ];
        return isset($list[$id]) ? $list[$id] : $list;
    }

    /**
     * 注册
     * @param array $data
     * @return array
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function reg($data = []){
        $res = self::model()->createOne($data);
        return $res;
    }
    
    /**
     * 
     *  根据条件修改
     */
    static function updateInfo($update, $map){
        $data = self::model()->where($map)
            ->update($update);
        return $data;
    }

    public static function getByUniqueId($unique_id = '')
    {
        return self::model()->where('unique_id', $unique_id)
            ->find();
    }

    public static function getByAppId($appid = '')
    {
        return self::model()->where('appid', $appid)
            ->find();
    }
}